package com.midea.ai.air.ui.more;

import android.app.Dialog;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import com.midea.ai.air.R;
import com.midea.ai.air.common.BaseActivity;
import com.midea.ai.air.view.MyTitleBar;

/**
 * Created by hww on 2016/3/24.
 * 更多-设置-反馈意见
 */
public class MoreSettingAdviceFeedback extends BaseActivity implements View.OnClickListener {

    private EditText advice_ed;
    private Dialog CommitS;
    private static final int SUCCESS_COMMIT_SUCCESS = 0X110;


    Handler handler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            switch (msg.what) {
                case SUCCESS_COMMIT_SUCCESS:
                    CommitS.dismiss();

                    MoreSettingAdviceFeedback.this.finish();
                    break;
                default:
                    break;
            }
        }
    };


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_moresettingadvicefeedback);

        init();
    }

    private TextView actionbar_right_tv;
    MyTitleBar myTitleBar;

    private void init() {
        myTitleBar = new MyTitleBar(this);
        myTitleBar.setActionBar_center(R.string.more_setting_advice_feedback);
        myTitleBar.setActioBar_left(false, 0, R.string.dialog_cancel);
        myTitleBar.setActionBar_right(true, R.string.register_commit);

        advice_ed = (EditText) findViewById(R.id.more_setting_advice_feedback_ed);

        actionbar_right_tv = (TextView) findViewById(R.id.actionbar_tv_right);
        actionbar_right_tv.setTextColor(getResources().getColor(R.color.electric_histogram));
        actionbar_right_tv.setAlpha(0.25f);
        CommitS = MoreSettingChangePassword.createLoadingDialog(MoreSettingAdviceFeedback.this, R.string.more_setting_advice_feedback_commit_success, R.drawable.register_dialog_success);


        //提交按钮激活
        advice_ed.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {
            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
                if (count < 0) {
                    actionbar_right_tv.setAlpha(0.25f);
                } else {
                    actionbar_right_tv.setAlpha(1f);
                }
            }

            @Override
            public void afterTextChanged(Editable s) {

            }
        });
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.actionbar_left_relativeLayout:
                //取消
                finish();
                break;
            case R.id.actionbar_tv_right:
                //提交

                CommitS.show();
                handler.sendEmptyMessageDelayed(SUCCESS_COMMIT_SUCCESS, 1000);
                break;
            default:
                break;
        }
    }

    //提交意见反馈内容
    private void adviceFeedbackCommit() {
        String content = advice_ed.getText().toString().trim();
    }

}
